package com.example.fms.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.fms.dto.req.AddMinOrderRuleReqDto;
import com.example.fms.dto.req.AddStandardFreightReqDto;
import com.example.fms.dto.req.StandardFreightReqDto;
import com.example.fms.dto.resp.StandardFreightRespDto;
import com.example.fms.service.StandardFreightRuleService;
import com.example.fms.vo.ResponseBean;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/standard")
public class StandardFreightRuleController {
    @Resource
    private StandardFreightRuleService standardFreightRuleService;

    /**
     * 查询标准查询
     * @param req 查询条件
     * @return 查询结果
     */
    @PostMapping("/getStandardFreightRuleList")
    public ResponseBean<Page<StandardFreightRespDto>> getStandardFreightList(@RequestBody StandardFreightReqDto req) {
        return ResponseBean.success(standardFreightRuleService.getStandardFreightList(req));
    }


    /**
     * 添加标准规则
     * @param req 新建数据
     * @return 是否成功
     */
    @PostMapping("/addStandardFreightRule")
    public ResponseBean<Boolean> addStandardFreightRule(@RequestBody @Valid AddStandardFreightReqDto req) {
        return ResponseBean.success(standardFreightRuleService.addStandardFreightRule(req));
    }

    /**
     * 修改标准规则
     * @param req 修改数据
     * @return 是否成功
     */
    @PutMapping("/upDateStandardFreightRule")
    public ResponseBean<Boolean> upDateStandardFreightRule(@RequestBody @Valid AddStandardFreightReqDto req) {
        return ResponseBean.success(standardFreightRuleService.upDateStandardFreightRule(req));
    }

    /**
     * 删除标准规则
     * @param id 删除数据的id
     * @return 是否成功
     */
    @DeleteMapping("/deleteStandardFreightRule/{id}")
    public ResponseBean<Boolean> deleteStandardFreightRule(@PathVariable("id")  Long id) {
        return ResponseBean.success(standardFreightRuleService.deleteStandardFreightRule(id));
    }
}
